<template>
    <div class="merchant_offer_discounts">
        <c-title :text="diy_name"></c-title>
        <div style="padding: .625rem;">
            <div class="box">
                <van-field v-model.trim="cashier_shop_commission" type="number" :label="'收银台'+diy_name+'比例'" placeholder="请输入比例"
                    input-align="right">
                    <template slot="right-icon">
                        %
                    </template>
                </van-field>
                <van-field v-model.trim="store_shop_commission" type="number" :label="'门店'+diy_name+'比例'" placeholder="请输入比例"
                    input-align="right">
                    <template slot="right-icon">
                        %
                    </template>
                </van-field>
            </div>
        </div>
        <div class="submit" @click="submit">提交</div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            store_shop_commission: "",
            diy_name: "",
            cashier_shop_commission: ""
        };
    },
    activated() {
        let plugin_setting = JSON.parse(localStorage.getItem("plugin_setting"));
        if (plugin_setting && plugin_setting.merchant_offer_discounts) {
            this.diy_name = plugin_setting.merchant_offer_discounts.diy_name;
            this.fun.setWXTitle(plugin_setting.merchant_offer_discounts.diy_name);
        }
        this.getData()
    },
    methods: {
        async submit() {
            let json = {
                store_id: this.$route.params.store_id * 1,
                store_shop_commission: this.store_shop_commission * 1,
                cashier_shop_commission: this.cashier_shop_commission * 1,
            }
            let {  msg ,result} = await $http.post("plugin.merchant-offer-discounts.frontend.controllers.index.update-store-setting", json, '.')
            this.$toast(msg);
            if(result){
                this.getData()
            }
        },
        async getData() {
            let { result, msg, data } = await $http.get("plugin.merchant-offer-discounts.frontend.controllers.index.index", { store_id: this.$route.params.store_id }, '.')
            if (result) {
                this.cashier_shop_commission = data.cashier_shop_commission * 1;
                this.store_shop_commission = data.store_shop_commission * 1;

            } else {
                this.$toast(msg);
            }
        }
    }
};
</script>

<style scoped lang='scss'>
::v-deep .van-field__label {
    width: unset;
}

::v-deep .van-cell {
    line-height: 35px;
}

.submit {
    border-radius: 1rem;
    color: #fff;
    text-align: center;
    margin: .625rem;
    background-color: #f14e4e;
    display: block;
    padding: .75rem 0;
    box-sizing: border-box;
}

.box {
    border-radius: 0.8rem;
    overflow: hidden;

}

/** **/
</style>